#include <windows.h>
#include <d3d11.h>
#include <d3dx11.h>
#include <d3dcompiler.h>
#include <xnamath.h>
#include <Camera.h>
#include <math.h>

Camera::Camera(int width, int height)
{
	viewportWidth = width;
	viewportHeight = height;
	m_fHorizontalAngle = 3.94f;
	m_fVerticalAngle = -0.82f;
	D3DXMATRIX mat;
	Up = D3DXVECTOR3( 0.0f, 1.0f, 0.0f );
	
}
void Camera::Init(void)
{
	cameraPos = D3DXVECTOR3( 131.0f, 131.0f, 124.0f );


	//cameraDirection = XMVector3Normalize(cameraDirection);
	
	cameraDirection =  D3DXVECTOR3( cosf(m_fHorizontalAngle) , sinf(m_fVerticalAngle), sinf(m_fHorizontalAngle));


	D3DXVec3Normalize(&cameraDirection, &cameraDirection);
}
D3DXMATRIX Camera::getViewMatrix(void)
{
	D3DXMATRIX matView, out;

	cameraDirection = D3DXVECTOR3( cosf(m_fHorizontalAngle) , sinf(m_fVerticalAngle), sinf(m_fHorizontalAngle) );
	
    D3DXVECTOR3 At = cameraPos + cameraDirection;

	D3DXMatrixLookAtLH( &matView, &cameraPos, &At, &Up );


	D3DXMatrixTranspose(&out, &matView);
	return out;

}
D3DXMATRIX Camera::getProjectionMatrix(void)
{
	D3DXMATRIX matProj, out;
	D3DXMatrixPerspectiveFovLH( &matProj, D3DX_PI / 4.0f, viewportWidth / (FLOAT)viewportHeight, 0.1f, 500.0f);
	//matProj = XMMatrixPerspectiveFovLH( XM_PIDIV4, viewportWidth / (FLOAT)viewportHeight, 0.01f, 500.0f );
	//matProj = XMMatrixTranspose( matProj );
	D3DXMatrixTranspose(&out, &matProj);
	return out;
}
D3DXVECTOR3 Camera::GetSideVector(void)
{
	D3DXVECTOR3 sideVector;
	D3DXVec3Cross(&sideVector, &Up, &cameraDirection);
	D3DXVec3Normalize(&sideVector, &sideVector);

	return sideVector;
}